const dbHelper = require("../app/lib/db/MySQLHelper");

// 获取sys模块菜单的sql
let sql = `SELECT * FROM mfplatformfunction WHERE assembly LIKE '%YlY2PRO.PlatForm.Sys.%'`;

let ylDatas = dbHelper.queryForList(sql, null, 1);
let spdDatas = dbHelper.queryForList(sql, null, 3);
let all = Promise.all([ylDatas, spdDatas]);

all.then(([source, target]) => {
  let needAdds = [];
  let props = Object.getOwnPropertyNames(target.datas[0]);

  source.datas.forEach(s => {
    if (
      target.datas.find(
        t =>
          t.PageID == s.PageID ||
          (t.PageKey == s.PageKey && t.Assembly == s.Assembly)
      ) == null
    ) {
      let obj = {};
      props.forEach(p => (obj[p] = s[p]));

      needAdds.push(obj);
    }
  });

  console.log(
    needAdds.map(n => {
      return { PageId: n.PageID, PageKey: n.PageKey };
    })
  );

  dbHelper
    .adds("mfplatformfunction", needAdds, 3)
    .then(rs => {
      console.log(rs);
    })
    .catch(err => {
      console.log(err);
    });
});
